package co.fitstart.admin.dao;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.demo2do.core.persistence.annotation.Dynamic;
import com.demo2do.core.persistence.annotation.Execute;
import com.demo2do.core.persistence.annotation.Limit;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;

import co.fitstart.entity.course.Course;
import co.fitstart.entity.course.CourseType;
import co.fitstart.entity.course.round.CourseRound;
import co.fitstart.entity.course.round.CourseRoundAttribute;
import co.fitstart.entity.course.round.CourseRoundGroup;
import co.fitstart.entity.course.round.CourseRoundResource;
import co.fitstart.entity.course.round.OnlineRoundGroupStatus;
import co.fitstart.entity.course.round.RoundStatus;
import co.fitstart.entity.course.schedule.ScheduleStatus;
import co.fitstart.entity.order.Order;
import co.fitstart.entity.site.Site;
import co.fitstart.entity.user.Student;
import co.fitstart.entity.user.User;

/**
 * 
 * @author lidan
 *
 */
@Dynamic("hibernate")
public interface CourseRoundDao {
    
    /**
     * 
     * @param courseType
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM CourseRound round WHERE round.disabled = false AND round.courseType = :courseType AND round.code != null GROUP BY round.code ORDER BY round.product.createTime DESC")
    public List<CourseRound> listOnlineRound(@Variable("courseType")CourseType courseType, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    /**
     * 
     * @param courseType
     * @param code
     * @return
     */
    @Query("FROM CourseRound round WHERE round.disabled = false AND round.courseType = :courseType AND round.code NOT LIKE :code AND round.code != null GROUP BY round.code")
    public List<CourseRound> listOnlineRound(@Variable("courseType")CourseType courseType, @Variable("code") String code);
    
    /**
     * 
     * @param courseType
     * @param courseStatus
     * @param experience 
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM CourseRound courseRound WHERE courseRound.disabled = false AND courseRound.courseType = :courseType AND courseRound.courseStatus = :courseStatus AND courseRound.course.experience = :experience AND courseRound.course.give = :give  ORDER BY courseRound.createTime DESC")
    public List<CourseRound> listIndividualRound(@Variable("courseType") CourseType courseType, @Variable("courseStatus") RoundStatus courseStatus, @Variable("experience") boolean experience, @Variable("give") boolean give, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    /**
     * 
     * @param site
     * @param courseType
     * @param courseStatus
     * @param experience
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM CourseRound courseRound WHERE courseRound.disabled = false AND courseRound.site = :site AND courseRound.courseType = :courseType AND courseRound.courseStatus = :courseStatus AND courseRound.course.experience = :experience AND courseRound.course.give = :give ORDER BY courseRound.createTime DESC")
    public List<CourseRound> listIndividualRound(@Variable("site") Site site, @Variable("courseType") CourseType courseType, @Variable("courseStatus") RoundStatus courseStatus, @Variable("experience") boolean experience, @Variable("give") boolean give, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    /**
     * 
     * @param sites
     * @param courseType
     * @param courseStatus
     * @param experience
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM CourseRound courseRound WHERE courseRound.disabled = false AND courseRound.site IN (:sites) AND courseRound.courseType = :courseType AND courseRound.courseStatus = :courseStatus AND courseRound.course.experience = :experience AND courseRound.course.give = :give ORDER BY courseRound.createTime DESC")
    public List<CourseRound> listIndividualRound(@Variable("sites") List<Site> sites, @Variable("courseType") CourseType courseType, @Variable("courseStatus") RoundStatus courseStatus, @Variable("experience") boolean experience, @Variable("give") boolean give, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    /**
     * 
     * @param courseType
     * @param courseStatus
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM CourseRound courseRound WHERE courseRound.disabled = false AND courseRound.courseType = :courseType AND courseRound.courseStatus = :courseStatus ORDER BY courseRound.createTime DESC")
    public List<CourseRound> listIndividualRound(@Variable("courseType") CourseType courseType, @Variable("courseStatus") RoundStatus courseStatus, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    /**
     * 
     * @param site
     * @param courseType
     * @param courseStatus
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM CourseRound courseRound WHERE courseRound.disabled = false AND courseRound.site = :site AND courseRound.courseType = :courseType AND courseRound.courseStatus = :courseStatus ORDER BY courseRound.createTime DESC")
    public List<CourseRound> listIndividualRound(@Variable("site") Site site, @Variable("courseType") CourseType courseType, @Variable("courseStatus") RoundStatus courseStatus, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    /**
     * 
     * @param sites
     * @param courseType
     * @param courseStatus
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM CourseRound courseRound WHERE courseRound.disabled = false AND courseRound.site IN (:sites) AND courseRound.courseType = :courseType AND courseRound.courseStatus = :courseStatus ORDER BY courseRound.createTime DESC")
    public List<CourseRound> listIndividualRound(@Variable("sites") List<Site> sites, @Variable("courseType") CourseType courseType, @Variable("courseStatus") RoundStatus courseStatus, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    
    /**
     * 
     * @param courseType
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM CourseRound courseRound WHERE courseRound.disabled = false AND courseRound.courseType = :courseType AND courseRound.code = null")
    public List<CourseRound> listArrangingGroupRound(@Variable("courseType") CourseType courseType, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    /**
     * 
     * @param site
     * @param courseType
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM CourseRound courseRound WHERE courseRound.disabled = false AND courseRound.code = null AND courseRound.site = :site AND courseRound.courseType = :courseType")
    public List<CourseRound> listArrangingGroupRound(@Variable("site") Site site, @Variable("courseType") CourseType courseType, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    /**
     * 
     * @param sites
     * @param courseType
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM CourseRound courseRound WHERE courseRound.disabled = false AND courseRound.code = null AND courseRound.site IN (:sites) AND courseRound.courseType = :courseType")
    public List<CourseRound> listArrangingGroupRound(@Variable("sites") List<Site> sites, @Variable("courseType") CourseType courseType, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    /**
     * 
     * @param courseType
     * @param courseStatus
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM CourseRound round WHERE round.disabled = false AND round.code is not null AND round.courseType = :courseType AND round.courseStatus = :courseStatus GROUP BY round.code")
    public List<CourseRound> listGroupRound(@Variable("courseType") CourseType courseType, @Variable("courseStatus") RoundStatus courseStatus, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    /**
     * 
     * @param site
     * @param courseType
     * @param courseStatus
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM CourseRound round WHERE round.disabled = false AND round.code is not null AND round.site = :site AND round.courseType = :courseType AND round.courseStatus = :courseStatus GROUP BY round.code")
    public List<CourseRound> listGroupRound(@Variable("site") Site site, @Variable("courseType") CourseType courseType, @Variable("courseStatus") RoundStatus courseStatus, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    /**
     * 
     * @param site
     * @param courseType
     * @param courseStatus
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM CourseRound round WHERE round.disabled = false AND round.code is not null AND round.site IN (:sites) AND round.courseType = :courseType AND round.courseStatus = :courseStatus GROUP BY round.code")
    public List<CourseRound> listGroupRound(@Variable("sites") List<Site> site, @Variable("courseType") CourseType courseType, @Variable("courseStatus") RoundStatus courseStatus, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    /**
     * 
     * @param courseType
     * @return
     */
    @Query("FROM CourseRound round WHERE round.disabled = false AND round.code is not null AND round.site is not null AND round.courseType = :courseType GROUP BY round.code")
    public List<CourseRound> listGroupRound(@Variable("courseType") CourseType courseType);
    
    /**
     * 
     * @param code
     * @param status
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM CourseRound round WHERE round.disabled = false AND round.courseStatus = :status AND round.code = :code")
    public List<CourseRound> listRoundByCode(@Variable("code") String code, @Variable("status") RoundStatus status, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
   
    /**
     * 
     * @param code
     * @param status
     * @return
     */
    @Query("FROM CourseRound round WHERE round.disabled = false AND round.courseStatus = :status AND round.code = :code")
    public List<CourseRound> listRoundByCode(@Variable("code") String code, @Variable("status") RoundStatus status);
    
    /**
     * @author Chang Liu
     * only list the courserounds which can be grouped (GROUPING, used for ungrouped onZip)
     * 
     * @param code
     * @param status
     * @param onlineRoundGroupStatus
     * @return
     */
    @Query("FROM CourseRound round WHERE round.disabled = false AND round.courseStatus = :status AND round.code = :code AND round.onlineRoundAttr.onlineRoundGroupStatus = :onlineRoundGroupStatus")
    public List<CourseRound> listRoundByCode(@Variable("code") String code, @Variable("status") RoundStatus status, @Variable("onlineRoundGroupStatus") OnlineRoundGroupStatus onlineRoundGroupStatus);
    
    /**
     * 
     * @param code
     * @param status
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM CourseRound round WHERE round.disabled = false AND round.onlineRoundAttr.onlineRoundGroupStatus in (:groupStatus) AND round.courseStatus = :status AND round.code = :code")
    public List<CourseRound> listUnfinishRoundByCode(@Variable("groupStatus") OnlineRoundGroupStatus[] onlineRoundGroupStatus, @Variable("code") String code, @Variable("status") RoundStatus status, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    /**
     * 
     * @param onlineRoundGroupStatus
     * @param code
     * @param status
     * @return
     */
    @Query("FROM CourseRound round WHERE round.disabled = false AND round.onlineRoundAttr.onlineRoundGroupStatus in (:groupStatus) AND round.courseStatus = :status AND round.code = :code")
    public List<CourseRound> listUnfinishRoundByCode(@Variable("groupStatus") OnlineRoundGroupStatus[] onlineRoundGroupStatus, @Variable("code") String code, @Variable("status") RoundStatus status);
    
    /**
     * 
     * @param code
     * @param status
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("SELECT group.courseRound FROM CourseRoundGroup group WHERE group.disabled = false AND group.courseRoundCode = :code AND group.name = :name ORDER BY group.courseRound.onlineRoundAttr.qrcodeStatus")
    public List<CourseRound> listfinishRoundByGroup(@Variable("code") String code, @Variable("name") String name, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    /**
     * 
     * @param code
     * @param name
     * @return
     */
    @Query("SELECT group.courseRound FROM CourseRoundGroup group WHERE group.disabled = false AND group.courseRoundCode = :code AND group.name = :name ORDER BY group.courseRound.onlineRoundAttr.qrcodeStatus")
    public List<CourseRound> listfinishRoundByGroup(@Variable("code") String code, @Variable("name") String name);
    
    /**
     * 
     * @param courseType
     * @param course
     * @return
     */
    @Query("SELECT new Map(id as id, student.name as student, site.name as site) FROM CourseRound courseRound WHERE courseRound.disabled = false AND courseRound.code = NULL AND courseRound.courseType = :courseType AND courseRound.course = :course")
    public List<Map<String, Object>> listRoundByCourse(@Variable("courseType") CourseType courseType, @Variable("course") Course course);
    
    /**
     * 
     * @param courseType
     * @param course
     * @param sites
     * @return
     */
    @Query("SELECT new Map(id as id, student.name as student, site.name as site) FROM CourseRound courseRound WHERE courseRound.disabled = false AND courseRound.code = NULL AND courseRound.courseType = :courseType AND courseRound.course = :course AND courseRound.site IN (:sites)")
    public List<Map<String, Object>> listRoundByCourse(@Variable("courseType") CourseType courseType, @Variable("course") Course course, @Variable("sites") List<Site> sites);
    
    /**
     * 
     * @param roundIds
     * @return
     */
    @Query("FROM CourseRound courseRound WHERE courseRound.disabled = false AND courseRound.id in (:roundIds)")
    public List<CourseRound> listCourseRound(@Variable("roundIds") List<Long> roundIds);
    
    /**
     * 
     * @param roundIds
     * @return
     */
    @Query("SELECT group.courseRound FROM CourseRoundGroup group WHERE group.disabled = false AND group.courseRoundCode = :code AND group.name =  :name AND group.courseRound.disabled = false AND group.courseRound.onlineRoundAttr.qrcodeStatus = true")
    public List<CourseRound> listCourseRound(@Variable("code") String code, @Variable("name") String groupName);
    
    /**
     * 
     * @param code
     * @param courseStatus 
     * @return
     */
    @Query("FROM CourseRound courseRound WHERE courseRound.disabled = false AND courseRound.code = :code AND courseRound.courseStatus in (:courseStatus) ORDER BY courseRound.courseStatus ASC")
    public List<CourseRound> listCourseRound(@Variable("code") String code, @Variable("courseStatus") List<RoundStatus> courseStatus);
    
    /**
     * 
     * @param course
     * @param courseStatus
     * @return
     */
    @Query("FROM CourseRound courseRound WHERE courseRound.disabled = false AND courseRound.code = NULL AND courseRound.courseStatus = :courseStatus AND courseRound.course = :course")
    public List<CourseRound> listCourseRound(@Variable("course") Course course, @Variable("courseStatus") RoundStatus courseStatus); 
    
    /**
     * 
     * @param groupStatus
     * @param status
     * @param code
     * @param startBmiValue
     * @param endBmiValue
     * @return
     */
    @Query("FROM CourseRound round WHERE round.disabled = false AND round.onlineRoundAttr.onlineRoundGroupStatus = :groupStatus AND round.courseStatus = :status AND round.code = :code AND onlineRoundAttr.oldStudent = :oldStudent ORDER BY onlineRoundAttr.bmiValue ASC")
    public List<CourseRound> listOnlineRound(@Variable("groupStatus") OnlineRoundGroupStatus groupStatus, @Variable("status") RoundStatus status, @Variable("code") String code, @Variable("oldStudent") boolean oldStudent);
    
    /**
     * 
     * @param code
     * @param status
     * @return
     */
    @Query("FROM CourseRound round WHERE round.disabled = false AND round.onlineRoundAttr.onlineRoundGroupStatus = :groupStatus AND round.onlineRoundAttr.qrcodeStatus = true AND round.courseStatus = :status AND round.code = :code")
    public List<CourseRound> listCourseRound(@Variable("groupStatus") OnlineRoundGroupStatus groupStatus, @Variable("code") String code, @Variable("status") RoundStatus status);
    
    /**
     * 
     * @param code
     * @param name
     * @return
     */
    @Query("SELECT group.courseRound.id FROM CourseRoundGroup group WHERE group.disabled = false AND group.courseRoundCode = :code AND group.name = :name")
    public List<Long> listCourseRoundId(@Variable("code") String code, @Variable("name") String name);
    
    /**
     * 
     * @param code
     * @return
     */
    @Query("FROM CourseRound courseRound WHERE courseRound.disabled = false AND courseRound.code = :code ORDER BY courseRound.courseStatus ASC")
    public CourseRound loadCourseRound(@Variable("code") String code);
    
    /**
     * 
     * @param order
     * @return
     */
    @Query("FROM CourseRound WHERE disabled = false AND order = :order")
    public CourseRound loadCourseRound(@Variable("order") Order order);
    
    /**
     * 
     * @param name
     * @param value
     * @return
     */
    @Query("FROM CourseRoundAttribute courseRoundAttribute WHERE courseRoundAttribute.name = :name AND courseRoundAttribute.value = :value")
    public CourseRoundAttribute loadCourseRoundAttribute(@Variable("name") String name, @Variable("value") String value);
     
    /**
     * 
     * @param code
     * @return
     */
    @Query("FROM CourseRoundResource WHERE code = :code")
    public CourseRoundResource loadCourseRoundResource(@Variable("code") String code);

    /**
     * 
     * @param student
     * @param courseTypes
     * @return
     */
    @Query("FROM CourseRound round WHERE round.disabled = false AND round.student = :student AND round.courseType in (:courseTypes)")
    public List<CourseRound> listCourseRound(@Variable("student") Student student, @Variable("courseTypes") CourseType[] courseTypes);
    
    /**
     * 
     * @param code
     * @return
     */
    @Query("FROM CourseRoundGroup WHERE disabled = false AND courseRoundCode = :code GROUP BY name")
    public List<CourseRoundGroup> listCourseRoundGroup(@Variable("code") String code);
    
    /**
     * 
     * @param code
     * @return
     */
    @Query("FROM CourseRoundGroup WHERE disabled = false AND courseRoundCode = :code GROUP BY name ORDER BY id DESC")
    public List<CourseRoundGroup> listOrderedCourseRoundGroup(@Variable("code") String code);
    
    /**
     * 
     * @param code
     * @param name
     * @return
     */
    @Query("SELECT COUNT(*) FROM CourseRoundGroup WHERE disabled = false AND courseRoundCode = :code AND name = :name")
    public int getRoundAmount(@Variable("code") String code, @Variable("name") String name);
    
    /**
     * 
     * @param status
     * @param code
     * @return
     */
    @Query("SELECT COUNT(*) FROM CourseRound WHERE onlineRoundAttr.onlineRoundGroupStatus = :groupStatus AND disabled = false AND courseStatus = :status AND code = :code")
    public int getFinishedInvestigateAmount(@Variable("groupStatus") OnlineRoundGroupStatus groupStatus, @Variable("status") RoundStatus status, @Variable("code") String code);
    
    /**
     * 
     * @param courseRound
     * @return
     */
    @Query("FROM CourseRoundGroup WHERE disabled = false AND courseRound = :courseRound")
    public CourseRoundGroup loadCourseRoundGroup(@Variable("courseRound") CourseRound courseRound);
    
    /**
     * 
     * @param type
     * @param student
     * @return
     */
    @Query("SELECT round.courseType FROM CourseRound round WHERE round.disabled = false AND round.courseType in (:type) AND round.student = :student GROUP BY round.courseType")
    public List<CourseType> listStudentCourse(@Variable("type") CourseType[] type, @Variable("student") Student student);
    
    /**
     * 
     * @param type
     * @param student
     * @param site
     * @return
     */
    @Query("SELECT round.courseType FROM CourseRound round WHERE round.disabled = false AND round.courseType in (:type) AND round.student = :student AND round.site = :site GROUP BY round.courseType")
    public List<CourseType> listStudentCourse(@Variable("type") CourseType[] type, @Variable("student") Student student, @Variable("site") Site site);
    
    /**
     * 
     * @param name
     * @param code
     * @param originalName
     */
    @Execute("UPDATE CourseRoundGroup SET name = :name WHERE courseRoundCode = :code AND name = :originalName")
    public void updateCourseRoundGroup(@Variable("name") String name, @Variable("code") String code, @Variable("originalName") String originalName);
    
    @Execute("UPDATE CourseRound SET onlineRoundAttr.zipName = :zipName WHERE order = :order")
    public void updateZipName(@Variable("zipName") String zipName, @Variable("order") Order order);
    
    @Query("SELECT round.order FROM CourseRound round WHERE round.disabled = false AND round.courseType = :type AND round.courseStatus = :status")
    public List<Order> listCourseRound(@Variable("type")CourseType type, @Variable("status")RoundStatus status);
    
    /**
     * list dishoesty round
     * @param dishonesty
     * @return
     */
    @Query("SELECT courseRound FROM CourseRoundAttribute WHERE name = 'dishonesty' AND value= :dishonesty")
    public List<CourseRound> listDishonestyRound(@Variable("dishonesty")String dishonesty);
    
    /**
     * 
     * @param scheduleStatus
     * @param user
     * @return
     */
    @Query("SELECT new Map(schedule.courseRound AS courseRound, MIN(schedule.occurDate) AS minOccurDate, MAX(schedule.occurDate) AS maxOccurDate) FROM CourseSchedule schedule WHERE schedule.disabled = false AND schedule.courseRound.disabled = false AND schedule.scheduleStatus = :scheduleStatus AND schedule.student.user = :user GROUP BY schedule.courseRound HAVING :day BETWEEN MIN(schedule.occurDate) AND MAX(schedule.occurDate)")
    public List<Map<String, Object>> listCourseRound(@Variable("scheduleStatus") ScheduleStatus scheduleStatus, @Variable("user") User user, @Variable("day") Date day);
    
    
    @Query("FROM CourseRound courseRound WHERE courseRound.disabled = false AND courseRound.student = :student ORDER BY createTime DESC")
    public List<CourseRound> listAll(@Variable("student") Student student);

    /**
     * 
     * @param courseType
     * @param courseStatuss
     * @param student
     * @return
     */
    @Query("FROM CourseRound courseRound WHERE courseRound.disabled = false AND courseRound.courseType = :courseType AND courseRound.courseStatus IN (:courseStatuss) AND courseRound.course.experience = false AND courseRound.course.give = false AND courseRound.student = :student ORDER BY createTime DESC")
    public List<CourseRound> listBindableMain(@Variable("courseType") CourseType courseType,@Variable("courseStatuss") List<RoundStatus> courseStatuss, @Variable("student") Student student);
    
    /**
     * 
     * @param courseType
     * @param courseId
     * @param courseStatuss
     * @param mobile
     * @return
     */
    @Query("FROM CourseRound courseRound WHERE courseRound.disabled = false AND courseRound.courseType = :courseType AND courseRound.courseStatus IN (:courseStatuss) AND courseRound.course.experience = true AND courseRound.course.id = :courseId AND courseRound.course.give = false AND courseRound.student.mobile = :mobile ORDER BY createTime DESC")
    public List<CourseRound> listExperience(@Variable("courseType") CourseType courseType, @Variable("courseId") Long courseId, @Variable("courseStatuss") List<RoundStatus> courseStatuss, @Variable("mobile") String mobile);
    
    /**
     * 
     * @param courseTypes
     * @param courseStatuss
     * @param mobile
     * @return
     */
    @Query("FROM CourseRound courseRound WHERE courseRound.disabled = false AND courseRound.courseType in (:courseTypes) AND courseRound.courseStatus IN (:courseStatuss) AND courseRound.course.experience = false AND courseRound.course.give = false AND courseRound.student.mobile = :mobile ORDER BY createTime DESC")
    public List<CourseRound> listOrderMain(@Variable("courseTypes") List<CourseType> courseTypes, @Variable("courseStatuss") List<RoundStatus> courseStatuss, @Variable("mobile") String mobile);
    
    
    @Query("FROM CourseRound courseRound WHERE courseRound.disabled = false AND courseRound.courseType in (:courseTypes) AND courseRound.courseStatus IN (:courseStatuss) AND courseRound.student.mobile = :mobile ORDER BY createTime DESC")
    public List<CourseRound> listAll(@Variable("courseTypes") List<CourseType> courseTypes, @Variable("courseStatuss") List<RoundStatus> courseStatuss, @Variable("mobile") String mobile);

    /**
     * 
     * @param courseType
     * @param courseStatuss
     * @param student
     * @param site
     * @return
     */
    @Query("FROM CourseRound courseRound WHERE courseRound.disabled = false AND courseRound.courseType = :courseType AND courseRound.courseStatus IN (:courseStatuss) AND courseRound.course.experience = false AND courseRound.course.give = false AND courseRound.student = :student AND courseRound.site = :site ORDER BY createTime DESC")
    public List<CourseRound> listBindableMain(@Variable("courseType") CourseType courseType,@Variable("courseStatuss") List<RoundStatus> courseStatuss, @Variable("student") Student student, @Variable("site") Site site);

    /**
     * 
     * @param courseType
     * @param courseStatuss
     * @param student
     * @param sites
     * @return
     */
    @Query("FROM CourseRound courseRound WHERE courseRound.disabled = false AND courseRound.courseType = :courseType AND courseRound.courseStatus IN (:courseStatuss) AND courseRound.course.experience = false AND courseRound.course.give = false AND courseRound.student = :student AND courseRound.site IN (:sites) ORDER BY createTime DESC")
    public List<CourseRound> listBindableMain(@Variable("courseType") CourseType courseType,@Variable("courseStatuss") List<RoundStatus> courseStatuss, @Variable("student") Student student, @Variable("sites") List<Site> sites);
}
